package com.leo.ktvplayer.boradcast;

import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.leo.ktvplayer.ui.login.ActLogin;

import java.util.List;

/**
 * Created by LeoLu on 2017/3/20.
 */

public class BootReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(0);
        if (!tasks.get(0).topActivity.getPackageName().equals("com.leo.ktvplayer")){
            Intent i = new Intent(context, ActLogin.class);
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(i);
        }
    }
}
